//
//  ImagesScrollViewController.m
//  HouseShow
//
//  Created by  on 11-12-23.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "ImagesScrollViewController.h"

#import "EGOPhotoViewController.h"
#import "MyPhoto.h"
#import "MyPhotoSource.h"
#import <QuartzCore/QuartzCore.h>

@interface ImagesScrollViewController(private) 
-(void) callEGOViewController;
@end

@implementation ImagesScrollViewController
@synthesize m_ImagesDataArr;
@synthesize m_PushNavigation;
@synthesize m_StartIndex;
@synthesize m_SrcData;
@synthesize m_NowIndex;
-(void) setM_PushNavigation:(UINavigationController *)f_PushNavigation{
    m_PushNavigation = nil;
    m_PushNavigation = f_PushNavigation;
    
    NSMutableArray* tScouse = [NSMutableArray array];
    NSMutableArray* tSmallScouse = [NSMutableArray array];
    int index = 0;
    
    UIImage* tDefaultSmall =[UIImage imageNamed:@"egopv_photo_placeholder.png"];
    
    for (NSDictionary* tDic in m_ImagesDataArr) {
        NSString* tSmallPath = [tDic objectForKey:@"imgsrc"];
        NSString* tBigPath =[tDic objectForKey:@"maximgsrc"];
        if (index == 1) {
           tBigPath = [tDic objectForKey:@"maximgsrc"];
        }
        NSLog(@"path =%@",tSmallPath);
        NSLog(@"big =%@",tBigPath);
        if ([tSmallPath isEqualToString:@""]) {
            continue;
        }
        MyPhoto * tEnumPhotoSmall = nil;
        if ([tSmallPath rangeOfString:@"http"].location != NSNotFound) {
                    tEnumPhotoSmall = [[MyPhoto alloc] initWithImage:tDefaultSmall];
        }else{
                    tEnumPhotoSmall = [[MyPhoto alloc] initWithImage:[UIImage imageWithContentsOfFile:tSmallPath]];
        }

        [tSmallScouse addObject:tEnumPhotoSmall];
        [tEnumPhotoSmall release];
        
        MyPhoto * tEnumPhoto = [[MyPhoto alloc] initWithImageURL:[NSURL URLWithString:tBigPath]];
        [tScouse addObject:tEnumPhoto];
        [tEnumPhoto release];
        index++;
    }
	MyPhotoSource *source = [[MyPhotoSource alloc] initWithPhotos:tScouse];
    MyPhotoSource *tSmall = [[MyPhotoSource alloc] initWithPhotos:tSmallScouse];
    
	p_photoController= [[EGOPhotoViewController alloc] initWithPhotoSource:source aPhotoSourcesmall:tSmall];
    p_photoController.m_NowIndex = m_NowIndex;
    p_photoController.m_SrcData = m_SrcData;
    p_photoController.m_AssignISVC =self;
    p_photoController.m_PageShowIndex = m_StartIndex;
    p_photoController.m_IsMagezin = NO;
	[source release];
    [tSmall release];
    
    
    [m_PushNavigation pushViewController:p_photoController animated:YES];
    
    [p_photoController moveToPhotoAtIndex:m_StartIndex animated:NO];
}

-(void) setMagezin {
    p_photoController.m_IsMagezin = YES;
}

-(void) dealloc{
    [p_photoController release];
    [m_ImagesDataArr release];
    [super dealloc];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

@end
